<template>
  <div class="switch-tab-placeholder">
    <div :class="['switch-tab-wrap', fixed ? 'fixed' : '']">
      <div class="switch-tab">
        <div
          :class="['switch-tab__item', key === value ? 'active' : '']"
          v-for="(item, key) in tabList"
          :key="key"
          @click="switchTab(key)"
        >{{ item }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ComSwitchTab',
  props: {
    // tab按钮列表
    tabList: {
      type: Array,
      default: (_) => [],
    },
    fixed: {
      type: Boolean,
      default: (_) => false,
    },
    // 当前选中的tab，双向绑定
    value: {
      type: [Number, String],
      default: 0,
    }
  },
  data () {
    return {}
  },
  created () {
  },
  mounted () {
  },
  methods: {
    switchTab (key) {
      this.$emit('input', key)
    }
  }
}
</script>
<style scoped lang="less">
.switch-tab-placeholder {
  background-color: #ccc;
  width: 100%;
  height: 60px
}

.switch-tab-wrap {
  display: flex;
  justify-content: center;
  background-color: #F8F8F8;
  padding: 15px 0;
  &.fixed {
    position: fixed;
    width: 100%;
    margin: 0 auto;
    left: 0;
    right: 0;
    z-index: 8;
  }

  .switch-tab {
    display: flex;
    background: #fff;
    box-shadow: 0 5px 10px 0 #ddd;
    border-radius: 15px;

    &__item {
      min-width: 100px;
      height: 30px;
      line-height: 30px;
      text-align: center;
      font-size: 14px;
      color: #118A84;

      &.active {
        background-color: #118A84;
        color: #fff;
        border-radius: 15px;
      }
    }
  }
}
</style>
